package com.neoCalf.neoAuth.controller;

import com.neoCalf.neoAuth.service.AuthService;
import com.neoCalf.neoCommon.entity.UserInfo;
import com.neoCalf.neoCommon.model.R;
import com.sun.istack.internal.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.Map;


/**
 * @author 小牛
 * @version 1.0
 * @description TODO
 * @date 2025/4/6 19:27
 */
@RestController
@RequestMapping("/auth")
@Validated
public class AuthController {
    @Resource
    private AuthService authService;

    @PostMapping("/token")
    public R<String> getToken(@RequestBody @NotNull UserInfo userInfo) {
        String token = authService.createToken(userInfo);
        return R.ok(token);
    }

    @GetMapping("check")
    public R<Map<String, Object>> validateToken(@RequestParam @NotEmpty String token, @RequestParam String role)  {
        Map<String, Object> map = authService.validateToken(token, role);
        return R.ok(map);
    }
}
